package com.tianzj.boot.mvc.repository.system;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.tianzj.boot.mvc.entity.system.SysMenu;

public interface SysMenuRepository extends JpaRepository<SysMenu, Long>,JpaSpecificationExecutor<SysMenu> {

	List<SysMenu> findByStatusNot(int i);

	List<SysMenu> findByParentIdEquals(Long id);

	List<SysMenu> findByStatusEquals(int i);

	@Query(value="select distinct sm.id , sm.parent_id, sm.name, sm.url,sm.auth_code,sm.type,sm.icon,sm.sort,sm.create_date,sm.create_user,sm.update_date,sm.update_user,sm.status from sys_menu sm "
			+ "left join sys_role_menu  srm on sm.id = srm.menu_id  "
			+ "left join sys_role sr on srm.role_id = sr.id "
			+ "left join sys_user_role sur on sur.role_id=sr.id "
			+ "left join sys_user  su on su.id=sur.user_id "
			+ "where su.id =?1 and sm.status = 1 and sm.type!=3 "
			+ "order by sm.sort asc",nativeQuery=true)
	List<SysMenu> findByUserId(Long id);

}
